//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __PUBCRT_H__
#define __PUBCRT_H__

#include <eltypes.h>

#if defined(_x86) || defined(_wince) || defined(__CEGCC__)
#define __LITTLE_ENDIAN
#endif

typedef union
{
#ifdef __LITTLE_ENDIAN
    struct
    {
        int lo, hi;
    } ints;
#else
    struct
    {
        int hi, lo;
    } ints;
#endif
    double d;
} fd_twoints;

#define __HI(x) x.ints.hi
#define __LO(x) x.ints.lo

#define EXP_MASK  0x7FF00000
#define DOUBLE_HI_MASK  ULLONG(0xffffffff00000000)
#define DOUBLE_LO_MASK  ULLONG(0x00000000ffffffff)
#define DOUBLE_FRACTION_MASK  ULLONG(0xfffffffffffff)
#define DOUBLE_EXP_MASK  ULLONG(0x7ff0000000000000)

#ifdef __cplusplus
extern "C" {
#endif

_ELASTOS Int32 _toWString(const char *encoding, wchar_t *dest,
                _ELASTOS Int32 *pdestSize,
                const char *src, _ELASTOS Int32 *psrcSize);
_ELASTOS Int32 _fromWString(const char *encoding, char *dest,
                _ELASTOS Int32 *pdestSize,
                const wchar_t *src, _ELASTOS Int32 *psrcSize);

size_t          __cdecl MbsToWcs(wchar_t *, const char *, size_t);
size_t          __cdecl WcsToMbs(char *, const wchar_t *, size_t);

char * CDECL GetEnv(const char *envstring);
wchar_t * CDECL WGetEnv(const wchar_t *envstring);
_ELASTOS ECode PutEnv(const char *strenv, const wchar_t *wcsenv);

_ELASTOS ECode WFullPath(wchar_t *absPath, const wchar_t *relPath, int maxlen);

_ELASTOS Boolean CDECL SetDevpath(int drive, wchar_t *pwszDevpath);
wchar_t * CDECL GetDevpath(int drive, wchar_t *pwszDevpath, int maxlen);

_ELASTOS ECode __stdcall CrtGetBootModule(const wchar_t *wszName,
                        _ELASTOS UInt32 *puAddr, _ELASTOS UInt32 *puSize);

_ELASTOS ECode __stdcall CrtFindService(
                 _ELASTOS WString wszName, IInterface **ppObj);

_ELASTOS ECode /* IApplet* */ __stdcall CrtGetCurrentAppletDir(_ELASTOS WStringBuf* pwsAppletDir);

_ELASTOS ECode CrtInitializeLock(_ELASTOS PVoid*);
_ELASTOS ECode CrtEnterLock(_ELASTOS PVoid);
_ELASTOS ECode CrtLeaveLock(_ELASTOS PVoid);
_ELASTOS ECode CrtDeleteLock(_ELASTOS PVoid*);

#ifdef __cplusplus
}
#endif

#endif //__PUBCRT_H__
